package com.xcl.controller;

import com.xcl.pojo.BreakmajorityEpiboly;
import com.xcl.service.XclBreakmajorityEpibolyServiceInter;
import com.zzg.entity.Logistics;
import com.zzg.entity.Outsourcing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName XclBreakmajorityEpibolyController
 * @Description 零担外包控制器
 * @Author: xiaochaolei
 * @date 2021/7/16 10:07
 * @Version 1. 0
 */
@Controller
public class XclBreakmajorityEpibolyController {
    @Autowired
    XclBreakmajorityEpibolyServiceInter xclBreakmajorityEpibolyServiceInter;

    /**
     * 查询以及多条件查询
     * @param page 页码数
     * @param limit 条目数
     * @param id 判断是查询还是多条件查询
     * @param sub_id 分站id
     * @param waybill_id 运单号
     * @param arrivalCity 到达城市
     * @param consignDate 日期
     * @return map类型的集合
     */
    @GetMapping(value = "/XclBreakmajorityEpibolyControllerGetBreakmajorityEpibolyAll", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> getBreakmajorityEpibolyAll(int page,int limit,String id,String sub_id,String waybill_id,String arrivalCity,String consignDate){
        Map<String,Object>  map=new HashMap<>();
        map.put("code","0");
        map.put("msg","0");
        if (id==null){
            map.put("count", xclBreakmajorityEpibolyServiceInter.getBreakmajorityEpibolyAll().size());
            map.put("data",xclBreakmajorityEpibolyServiceInter.getBreakmajorityEpibolyByLimit(page,limit));
            return map;
        }else {
            map.put("count", xclBreakmajorityEpibolyServiceInter.getBreakmajorityEpibolyByWhere(page,limit,sub_id,waybill_id,arrivalCity,consignDate).size());
            map.put("data",xclBreakmajorityEpibolyServiceInter.getBreakmajorityEpibolyByWhere(page,limit,sub_id,waybill_id,arrivalCity,consignDate));
            return map;
        }
    }

    /**
     * 根据id查询
     * @param id 运单号
     * @return
     */
    @PostMapping(value = "/XclBreakmajorityEpibolyControllerGetBreakmajorityEpibolyById", produces = "application/json;charset=utf-8")
    @ResponseBody
    public BreakmajorityEpiboly getBreakmajorityEpibolyById(String id){
        return xclBreakmajorityEpibolyServiceInter.getBreakmajorityEpibolyById(id);
    }

    /**
     * 得到所有的物流承担商
     * @return 承担商集合
     */
    @PostMapping(value = "/XclBreakmajorityEpibolyControllerGetAllConsignerByPhone",produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> getAllConsignerByPhone(){
        Map<String,Object> map = new HashMap<>();
        map.put("index",0);
        map.put("data",xclBreakmajorityEpibolyServiceInter.getLogisticsAll());
        //返回map集合
        return map;
    }

    /**
     * 根据id得到物流承担商的信息
     * @param id 物流承担商的id
     * @return 物流承担商的信息
     */
    @PostMapping(value = "/XclBreakmajorityEpibolyControllerGetLogisticsById",produces = "application/json;charset=utf-8")
    @ResponseBody
    public Logistics getLogisticsById(String id){
      return xclBreakmajorityEpibolyServiceInter.getLogisticsById(id);
    }

    /**
     * 查询外包单号是否存在
     * @param outsourcingOrder 外包单号
     * @return 外包信息
     */
    @PostMapping(value = "/XclBreakmajorityEpibolyControllerGetOutsourcingByOutsourcingOrder",produces = "application/json;charset=utf-8")
    @ResponseBody
    public Outsourcing getOutsourcingByOutsourcingOrder(double outsourcingOrder){
        return xclBreakmajorityEpibolyServiceInter.getOutsourcingByOutsourcingOrder(outsourcingOrder);
    }








    @PostMapping(value = "/XclBreakmajorityEpibolyControllerInsertElseRpiboly",produces = "application/text;charset=utf-8")
    @ResponseBody
    public String insertElseRpiboly(Logistics logistics, Outsourcing  outsourcing,String location,String id){
        xclBreakmajorityEpibolyServiceInter.insertElseRpiboly(logistics,outsourcing,location,id);
        return "成功";
    }
}
